package ioperation;

import book.Book;
import book.BookList;

import javax.script.ScriptContext;
import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        //判断是否满书
        int currentSize=bookList.getUsedSize();//获取图书数量
        if(currentSize==bookList.getBooks().length){
            System.out.println("书架已满");
            return;
        }
        System.out.println("图书增加");
        Scanner scanner=new Scanner(System.in);
        System.out.println("输入书名");
        String name=scanner.nextLine();
        System.out.println("输入作者");
        String author=scanner.nextLine();
        System.out.println("输入类型");
        String type=scanner.nextLine();
        System.out.println("输入价格");
        int price=scanner.nextInt();

        Book newBook=new Book(name,author,price,type);
        bookList.setBook(currentSize,newBook);
        System.out.println("增加成功");
        bookList.setUsedSize(currentSize+1);
        return;
    }
}
